package leetcode.code1599;

import leetcode.IDebug;

public class Solution implements IDebug {

	public int minOperationsMaxProfit(int[] customers, int boardingCost, int runningCost) {
		int ans = 0, max = Integer.MIN_VALUE, run = 1;
		int wait = 0, sum = 0;
		for (int i = 0; i < customers.length; i++, run++) {
			wait += customers[i];
			int board = Math.min(wait, 4);
			sum += board * boardingCost;
			sum -= runningCost;
			if (sum > max) {
				max = sum;
				ans = run;
			}
			wait -= board;
		}
		while (wait > 0) {
			int board = Math.min(wait, 4);
			sum += board * boardingCost;
			sum -= runningCost;
			if (sum > max) {
				max = sum;
				ans = run;
			}
			wait -= board;
			run++;
		}
		return max <= 0 ? -1 : ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
